<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>卡拉卡-在线选号平台</title>
		<link href="/css/style.css" rel="stylesheet" type="text/css" />
		<link href="/css/win.css" rel="stylesheet" type="text/css" />
		<link href="/css/pagination.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="../js/jquery-1.7.min.js"></script>
		<script type="text/javascript" src="../js/jquery.cookie.js"></script>
		<script type="text/javascript" src="../js/jquery.pagination.js"></script>
		<script type="text/javascript" src="../js/logon.js"></script>
		<script type="text/javascript" src="../js/jquery.blockUI.js"></script>
		<script type="text/javascript" src="../js/ajaxfileupload.js"></script>
		<script language="javascript" type="text/javascript">
			var page = 0; //页面索引初始值
			var pageSize = 9; //每页显示条数初始化，修改显示条数，修改这里即可
			$(function () {
				//initTable(10); //Load事件，初始化表格数据，页面索引为0（第一页）
				//分页，PageCount是总条目数，这是必选参数，其它参数都是可选
				$("#Pagination").pagination($!{model.get("count")}, {
					callback:PageCallback, //PageCallback() 为翻页调用次函数。
					prev_text:"上一页",
					next_text:"下一页",
					items_per_page:pageSize,
					num_edge_entries:2, //两侧首尾分页条目数
					num_display_entries:3, //连续分页主体部分分页条目数
					current_page:page, //当前页索引
				});
				//翻页调用
				function PageCallback(page,jq) {
					initTable(page);
				}
				//请求数据
				function initTable(page) {
					$.ajax({
						type:"POST",
						dataType:"text",
						url:"/admin/phone/page", //提交到一般处理程序请求数据
						data:{page:page+1,pageSize:pageSize,carrier:'$!{model.get("carrier")}',brand:'$!{model.get("brand")}',_status:'$!{model.get("_status")}',keyword:'$!{model.get("keyword")}'}, //提交两个参数：pageIndex(页面索引)，pageSize(显示条数)
						success:function(data){
						//alert(data);
							$('#list-content').html('');
							$('#list-content').html(data);
							//$("#Result tr:gt(0)").remove();//移除Id为Result的表格里的行，从第二行开始（这里根据页面布局不同页变）
							//$("#Result").append(data); //将返回的数据追加到表格
						}
					});
				}
			});
			
			function search()
			{
				$('#searchForm').attr("action", "/admin/phone");
				$("#searchForm").target="_self";
				$("#searchForm").submit();
			}
			
			function showD()
			{
				$.blockUI({ message: $('#pop')});
			}
			function importFile()
			{
				var filename =$.trim($("#textfield").val());
			    if(filename!=''){
				 	$.ajaxFileUpload({ //一个Ajax过程 
						type: "post", //以post方式与后台沟通 
						url : "/admin/phone/import",
						secureuri: false, 
			          	fileElementId: 'fileField',
				     	dataType:'json',
				     	success: function(data)
				     	{
							alert(data);
							$("#searchForm").submit();
							$("#textfield").val("");
							$.unblockUI();
						}
					});
				}else{
					alert("请选择文件!");
				}
			}
			function hideD()
			{
				$.unblockUI();
			}
			
			//打开号码信息框
			function detail(obj,status)
			{
				$.ajax({    
			        type:'post',
			        url:'/admin/phone/detail',
			        data:{pid:obj},
			        cache:false,
			        async:false,
			        dataType:'json',
			        success:function(data){
			        	if(data=="error")
			        	{
			        		alert(data);
			        	}
			        	else
			        	{
			        		$("#pid").val(data.pid);
			        		$("#status").val(data.status);
			        		$("#phone").text(data.phone);
			        		var carrier=data.carrier==1?"中国移动":data.carrier==2?"中国联通":data.carrier==3?"中国电信":"";
			        		$("#carrier").text(carrier);
			        		$("#retail").val(data.retail/100);
			        		$("#discount").val(data.discount/100);
			        		$("#province").val(data.province);
			        		$("#city").val(data.city);
			        		var status=data.status==1?"未开卡":data.status==2?"已锁定":data.status==3?"已开卡":data.status==4?"已下架":"";
			        		$("#state").text(status);
			        		
			        		if(data.status ==1)
			        		{
								$("#Submit1").css("display","");
								$("#shelve").css("display","");
			        			$("#shelve").val("下架");
			        		}
			        		if(data.status ==2 || data.status ==3)
			        		{
								$("#Submit1").css("display","none");
								$("#shelve").css("display","none");
			        		}
			        		if(data.status ==4)
			        		{
								$("#Submit1").css("display","");
								$("#shelve").css("display","");
			        			$("#shelve").val("上架");
			        		}
							$.blockUI({ message: $('#pop2')});
			        	}
			        },
			        error: function(){  //失败
				        alert('Error loading document');
				    }
			    });  
			}
			
			//提交修改
			function modPhone()
			{
				var formParam = $("#phoneForm").serialize();
				$.ajax({
				        type:'post',
				        url:'/admin/phone/mod',
				        data:formParam,
				        cache:false,
				        async:false,
				        dataType:'json',
				        success:function(data){
				        	if(data.msg =="true" ){
				        		alert("修改成功！");
				        		$("#phone").text("");
				        		$("#carrier").text("");
				        		$("#retail").val("");
				        		$("#discount").val("");
				        		$("#province").val("");
				        		$("#city").val("");
				        		$("#status").text("");
					        }else{
					            alert("失败，请重试！");
					        }
					        $.unblockUI();
				        },
				        error: function(){  //失败
					        alert('Error loading document');
					        $.unblockUI();
					    }
				    });
			}
			
			//上/下架
			function doShelve()
			{
				var formParam = $("#phoneForm").serialize();
				$.ajax({
				        type:'post',
				        url:'/admin/phone/shelve',
				        data:formParam,
				        cache:false,
				        async:false,
				        dataType:'json',
				        success:function(data){
				        	if(data.msg =="true" ){
				        		alert("操作成功！");
					        }else{
					            alert("失败，请重试！");
					        }
					        $.unblockUI();
				        },
				        error: function(){  //失败
					        alert('Error loading document');
					        $.unblockUI();
					    }
				    });
			}
			
			//清除号码
			function clear()
			{
				var carrier = $("#_carrier").val();
				var brand = $("#brand").val();
				//alert(brand);
				if(brand==-1)
				{
					alert("请先选择一个品牌");
				}
				if(confirm("号码将被彻底清除，确定清除吗？"))
				{
					$.ajax({
				        type:'post',
				        url:'/admin/phone/clear',
				        data:{carrier:carrier,brand:brand},
				        cache:false,
				        async:false,
				        dataType:'json',
				        success:function(data){
				        	if(data.msg =="true" ){
				        		alert("清除成功！");
								$('#searchForm').attr("action", "/admin/phone");
								$("#searchForm").target="_self";
								$("#searchForm").submit();
					        }else{
					            alert("失败，请重试！");
					        }
				        },
				        error: function(){  //失败
					        alert('Error loading document');
					    }
				    });
				}
			}
			
			//导出号码
			function exportX()
			{
				$('#searchForm').attr("action", "/admin/phone/export");
				$("#searchForm").target="_self";
				$("#searchForm").submit();
			}
		</script>
	</head>

	<body>
		<!--首先设置一个层:-->
		<div id="pop" class="sow" style="display:none"> 
			<div class="sowbody">
				<div class="pop_title"><span>导入文件</span></div>
				<div class="file-box">
				<form action="" method="post" enctype="multipart/form-data">
				<table width="100%" border="0" cellspacing="0" cellpadding="8" class="pop_table">
	  				<tr>
						<td height="120" colspan="2" align="center" valign="middle">
						<input type='text' name='textfield' id='textfield' class='txt' /> 
						<input type='button' class='btn' value='浏览...' onclick="fileField.click();"/> 
						<input type="file" name="fileField" class="file" id="fileField" size="28" onchange="document.getElementById('textfield').value=this.value" />
		  				</td>
	  				</tr>
	  				<tr>
					<td align="center" class="td_n">
						<input type="button" name="Submit" value="确定" class="out_btn"  onclick="importFile();"/> 
						<input type="button" name="Submit" value="取消" class="out_btn"  onclick="hideD()"/></td>
	  				</tr>
  				</table>
  				</form>
  				</div>
			</div> 
		</div>
		<div id="pop2" class="pop" style="display:none">
			<div class="pop_body">
				<div class="pop_title">详细信息</div>
				<form id="phoneForm" name="phoneForm" action="/admin/phone/mod" method="post">
				<input type="hidden" id="pid" name="pid"/>
				<input type="hidden" id="status" name="status"/>
				<table width="100%" border="0" cellspacing="0" cellpadding="6" class="pop_table">
					<tr>
						<td width="18%" align="center" valign="top" class="line">号码：</td>
						<td colspan="3" class="line" id="phone"></td>
					</tr>
					<tr>
						<td align="center" valign="top" class="line">运营商：</td>
						<td colspan="3" class="line" id="carrier"></td>
					</tr>
					<tr>
						<td align="center" valign="top" class="line">零售价：</td>
						<td class="line"><input type="text" id="retail" name="retail" style="border:#999 1px solid;" maxlength="8"/></td>
						<td class="line">折扣价：</td>
						<td class="line"><input type="text" id="discount" name="discount" style="border:#999 1px solid;" maxlength="8"/></td>
					</tr>
					<tr>
						<td align="center" valign="top" class="line">所在省：</td>
						<td class="line"><input type="text" id="province" name="province" style="border:#999 1px solid;" maxlength="32"/></td>
						<td class="line">所在市：</td>
						<td class="line"><input type="text" id="city" name="city" style="border:#999 1px solid;" maxlength="32"/></td>
					</tr>
					<tr>
						<td align="center" valign="top" class="line">状态：</td>
						<td colspan="3" class="line" id="state"></td>
					</tr>
					<tr>
						<td align="center" valign="top" class="line">&nbsp;</td>
						<td colspan="3" class="line"></td>
					</tr>
					<tr>
						<td align="center" valign="top" class="line">&nbsp;</td>
						<td colspan="3" class="line"></td>
					</tr>
					<tr>
						<td colspan="4" align="center" class="td_n">
							<input type="button" id="Submit1" name="Submit1" value="保存" class="out_btn"  onclick="modPhone();"/> 
							<input type="button" id="shelve" name="Submit2" value="下架" class="out_btn" onclick="doShelve();"/> 
							<input type="button" name="Submit3" value="取消" class="out_btn"  onclick="hideD();"/>
						</td>
					</tr>
				</table>
				</form>
			</div>
		</div>
		#include("header.html")
		<table width="100%" border="0" cellspacing="0" cellpadding="0" id="content">
			<tr><td valign="top" id="menu">
			#include("menu_admin.html")
			</td>
			<td id="right">
				<div id="order">
					<form id="searchForm" name="searchForm" action="/admin/phone" method="post">
					<div class="title">
						<span>首页 &gt; 号码管理</span>
					</div>
					<div class="step">
						运营商：
						<select id="_carrier" name="carrier">
							<option value="-1">全部</option>
							<option value="1" #if($!{model.get("carrier")}==1) selected #end>中国移动</option>
							<option value="2" #if($!{model.get("carrier")}==2) selected #end>中国联通</option>
							<option value="3" #if($!{model.get("carrier")}==3) selected #end>中国电信</option>
						</select>&nbsp;&nbsp;
						<select id="brand" name="brand">
							<option value="-1">全部</option>
							#if($!{model.get("carrier")}==1)
							<option value="10" #if($!{model.get("brand")}==10) selected #end>全球通</option>
							<option value="41" #if($!{model.get("brand")}==41) selected #end>动感地带网聊卡</option>
							<option value="42" #if($!{model.get("brand")}==42) selected #end>动感地带3G流量卡</option>
							<option value="71" #if($!{model.get("brand")}==71) selected #end>神州行3G流量卡</option>
							<option value="72" #if($!{model.get("brand")}==72) selected #end>神州行轻松卡</option>
							#elseif($!{model.get("carrier")}==2)
							<option value="20" #if($!{model.get("brand")}==20) selected #end>联通3G</option>
							<option value="21" #if($!{model.get("brand")}==21) selected #end>如意通</option>
							<option value="22" #if($!{model.get("brand")}==22) selected #end>特区行</option>
							<option value="81" #if($!{model.get("brand")}==81) selected #end>up新势力先锋卡</option>
							<option value="82" #if($!{model.get("brand")}==82) selected #end>up新势力流量卡</option>
							#elseif($!{model.get("carrier")}==3)
							<option value="3" #if($!{model.get("brand")}==3) selected #end>中国电信</option>
							#end
						</select>&nbsp;&nbsp;
						<select name="_status">
							<option value="-1">全部</option>
							<option value="1" #if($!{model.get("_status")}==1) selected #end>未开卡</option>
							<option value="2" #if($!{model.get("_status")}==2) selected #end>已锁定</option>
							<option value="3" #if($!{model.get("_status")}==3) selected #end>已开卡</option>
							<option value="4" #if($!{model.get("_status")}==4) selected #end>已下架</option>
						</select>&nbsp;&nbsp;
						关键字：
						<input type="text" name="keyword" class="sou_input" value="$!{model.get("keyword")}"/>
						<input type="button" name="Submit" value="查询" class="out_btn" onclick="search();" />
					</div>
					</form>
				</div>
				<div id="list">
					<div class="title" style="font-size:13px;font-weight:600;display:none">
						<span>查询结果</span>
					</div>
					<div class="data">
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<thead>
							<tr>
								<td>手机号码</td>
								<td width="120">运营商</td>
								<td width="100">零售价</td>
								<td width="100">折扣价</td>
								<td width="60">状态</td>
								<td width="60">操作</td>
							</tr>
							</thead>
							<tbody id="list-content">
							</tbody>
							<tr>
								<td colspan="6">
									<table width="100%" border="0" cellspacing="0" cellpadding="0">
										<tr>
											<td>
												<a href="javascript:void(0);" id="btn_import" onclick="showD();">导入</a>&nbsp;&nbsp;
												<a href="javascript:clear();" id="btn_import" onclick="clear();">清除</a>&nbsp;&nbsp;
												<a href="javascript:void(0);" id="btn_export" onclick="exportX();">导出</a>
											</td>
											<td><div id="Pagination" class="pagination" style="margin:4px 0 0 0"></div></td>
											<td width="80">共$!{model.get("count")}条</td>
										</tr>
									</table>
								</td>
							</tr>
						</table>
					</div>
				</div>
				</td></tr></table>
		#include("footer.html")
	</body>
</html>
